package boogui.member;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

public class S_MemberFindDialog extends JDialog {
	private JTextField nametf;
	private JTextField emailtf;
	private JTextField idtf;
	private JTextField nametf2;
	private JTextField emailtf2;
	
	private BtnActionListener al = null;
	
	public S_MemberFindDialog(JFrame p) {
		super(p);
		setModalityType(ModalityType.DOCUMENT_MODAL);
		setIconImage(Toolkit.getDefaultToolkit().getImage(S_MemberFindDialog.class.getResource("/images/user.png")));
		setTitle("아이디 / 비밀번호 찾기");
		setSize(400, 300);
		setModalityType(ModalityType.DOCUMENT_MODAL);
		setResizable(false);
		setLocationRelativeTo(null);
		
		
		al = new BtnActionListener();
		
		getContentPane().setLayout(new BorderLayout());
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton cancelButton = new JButton("닫기");
				cancelButton.addActionListener(al);
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
		{
			JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);			
			getContentPane().add(tabbedPane, BorderLayout.CENTER);
			{
				JPanel panel = new JPanel();
				tabbedPane.addTab("아이디 찾기", null, panel, null);				
				GridBagLayout gbl_panel = new GridBagLayout();
				gbl_panel.columnWidths = new int[] {0, 0, 0, 0, 0, 0};
				gbl_panel.rowHeights = new int[] {0, 0, 15, 0, 15, 0, 15, 0};
				gbl_panel.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
				gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
				panel.setLayout(gbl_panel);
				{
					JLabel lblNewLabel = new JLabel("아이디 찾기");
					lblNewLabel.setFont(new Font("맑은 고딕", Font.BOLD, 16));
					GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
					gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
					gbc_lblNewLabel.gridx = 1;
					gbc_lblNewLabel.gridy = 1;
					panel.add(lblNewLabel, gbc_lblNewLabel);
				}
				{
					JLabel namelbl = new JLabel("이     름");
					GridBagConstraints gbc_namelbl = new GridBagConstraints();
					gbc_namelbl.insets = new Insets(0, 0, 5, 5);
					gbc_namelbl.gridx = 1;
					gbc_namelbl.gridy = 3;
					panel.add(namelbl, gbc_namelbl);
				}
				{
					nametf = new JTextField();
					nametf.setMargin(new Insets(3, 5, 3, 3));
					GridBagConstraints gbc_nametf = new GridBagConstraints();
					gbc_nametf.gridwidth = 3;
					gbc_nametf.insets = new Insets(0, 0, 5, 0);
					gbc_nametf.fill = GridBagConstraints.HORIZONTAL;
					gbc_nametf.gridx = 3;
					gbc_nametf.gridy = 3;
					panel.add(nametf, gbc_nametf);
					nametf.setColumns(10);					
				}
				{
					JLabel emaillbl = new JLabel("이 메 일");
					GridBagConstraints gbc_emaillbl = new GridBagConstraints();
					gbc_emaillbl.insets = new Insets(0, 0, 5, 5);
					gbc_emaillbl.gridx = 1;
					gbc_emaillbl.gridy = 5;
					panel.add(emaillbl, gbc_emaillbl);
				}
				{
					emailtf = new JTextField();
					emailtf.setMargin(new Insets(3, 5, 3, 3));
					GridBagConstraints gbc_emailtf = new GridBagConstraints();
					gbc_emailtf.insets = new Insets(0, 0, 5, 0);
					gbc_emailtf.gridwidth = 3;
					gbc_emailtf.fill = GridBagConstraints.HORIZONTAL;
					gbc_emailtf.gridx = 3;
					gbc_emailtf.gridy = 5;
					panel.add(emailtf, gbc_emailtf);
					emailtf.setColumns(20);
				}
				{
					JButton idFindBtn = new JButton("아이디 찾기");
					idFindBtn.addActionListener(al);
					idFindBtn.setActionCommand("findid");
					GridBagConstraints gbc_idFindBtn = new GridBagConstraints();
					gbc_idFindBtn.anchor = GridBagConstraints.EAST;
					gbc_idFindBtn.gridx = 5;
					gbc_idFindBtn.gridy = 7;
					panel.add(idFindBtn, gbc_idFindBtn);
				}
			}
			{
				JPanel panel = new JPanel();
				tabbedPane.addTab("비밀번호 찾기", null, panel, null);
				GridBagLayout gbl_panel = new GridBagLayout();
				gbl_panel.columnWidths = new int[] {0, 0, 0, 0, 0, 0};
				gbl_panel.rowHeights = new int[] {0, 0, 10, 0, 10, 0, 10, 0, 10, 0};
				gbl_panel.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
				gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
				panel.setLayout(gbl_panel);
				{
					JLabel lblNewLabel_3 = new JLabel("비밀번호 찾기");
					lblNewLabel_3.setFont(new Font("맑은 고딕", Font.BOLD, 16));
					GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
					gbc_lblNewLabel_3.insets = new Insets(0, 0, 5, 5);
					gbc_lblNewLabel_3.gridx = 1;
					gbc_lblNewLabel_3.gridy = 1;
					panel.add(lblNewLabel_3, gbc_lblNewLabel_3);
				}
				{
					JLabel lblNewLabel_4 = new JLabel("아 이 디");
					GridBagConstraints gbc_lblNewLabel_4 = new GridBagConstraints();
					gbc_lblNewLabel_4.insets = new Insets(0, 0, 5, 5);
					gbc_lblNewLabel_4.gridx = 1;
					gbc_lblNewLabel_4.gridy = 3;
					panel.add(lblNewLabel_4, gbc_lblNewLabel_4);
				}
				{
					idtf = new JTextField();
					idtf.setMargin(new Insets(3, 3, 3, 3));
					GridBagConstraints gbc_idtf = new GridBagConstraints();
					gbc_idtf.gridwidth = 3;
					gbc_idtf.insets = new Insets(0, 0, 5, 0);
					gbc_idtf.fill = GridBagConstraints.HORIZONTAL;
					gbc_idtf.gridx = 3;
					gbc_idtf.gridy = 3;
					panel.add(idtf, gbc_idtf);
					idtf.setColumns(15);
				}
				{
					JLabel lblNewLabel_5 = new JLabel("이     름");
					GridBagConstraints gbc_lblNewLabel_5 = new GridBagConstraints();
					gbc_lblNewLabel_5.insets = new Insets(0, 0, 5, 5);
					gbc_lblNewLabel_5.gridx = 1;
					gbc_lblNewLabel_5.gridy = 5;
					panel.add(lblNewLabel_5, gbc_lblNewLabel_5);
				}
				{
					nametf2 = new JTextField();
					nametf2.setMargin(new Insets(3, 3, 3, 3));
					GridBagConstraints gbc_nametf2 = new GridBagConstraints();
					gbc_nametf2.gridwidth = 3;
					gbc_nametf2.insets = new Insets(0, 0, 5, 0);
					gbc_nametf2.fill = GridBagConstraints.HORIZONTAL;
					gbc_nametf2.gridx = 3;
					gbc_nametf2.gridy = 5;
					panel.add(nametf2, gbc_nametf2);
					nametf2.setColumns(10);
				}
				{
					JLabel lblNewLabel_6 = new JLabel("이 메 일");
					GridBagConstraints gbc_lblNewLabel_6 = new GridBagConstraints();
					gbc_lblNewLabel_6.insets = new Insets(0, 0, 5, 5);
					gbc_lblNewLabel_6.gridx = 1;
					gbc_lblNewLabel_6.gridy = 7;
					panel.add(lblNewLabel_6, gbc_lblNewLabel_6);
				}
				{
					emailtf2 = new JTextField();
					emailtf2.setMargin(new Insets(3, 3, 3, 3));
					GridBagConstraints gbc_emailtf2 = new GridBagConstraints();
					gbc_emailtf2.gridwidth = 3;
					gbc_emailtf2.insets = new Insets(0, 0, 5, 0);
					gbc_emailtf2.fill = GridBagConstraints.HORIZONTAL;
					gbc_emailtf2.gridx = 3;
					gbc_emailtf2.gridy = 7;
					panel.add(emailtf2, gbc_emailtf2);
					emailtf2.setColumns(20);
				}
				{
					JButton findPwdBtn = new JButton("비밀번호 찾기");
					GridBagConstraints gbc_findPwdBtn = new GridBagConstraints();
					findPwdBtn.addActionListener(al);
					findPwdBtn.setActionCommand("findpwd");
					gbc_findPwdBtn.anchor = GridBagConstraints.EAST;
					gbc_findPwdBtn.gridx = 5;
					gbc_findPwdBtn.gridy = 9;
					panel.add(findPwdBtn, gbc_findPwdBtn);
				}
			}
		}
		
		setVisible(true);
	}
	
	private class BtnActionListener implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {
			IMemberFindService fs = new MemberFindService();
			MemberVO m = new MemberVO();
			String msg = "";			
			switch (e.getActionCommand()) {			
			case "findid":
				m.setMemname(nametf.getText());
				m.setMememail(emailtf.getText());
				if (nametf.getText().length() == 0) {
					msg = "이름을 입력하세요.";
					nametf.requestFocus();
				} else if (emailtf.getText().length() == 0) {
					msg = "이메일을 입력하세요.";
					emailtf.requestFocus();
				} else {
					msg = fs.searchId(m);
				}				
				JOptionPane.showMessageDialog(null, msg, "",JOptionPane.WARNING_MESSAGE);
				break;
			case "findpwd":
				
				m.setMemid(idtf.getText());				
				m.setMemname(nametf2.getText());
				m.setMememail(emailtf2.getText());
				if (idtf.getText().length() == 0) {
					msg = "아이디를 입력하세요.";
					JOptionPane.showMessageDialog(null, msg, "",JOptionPane.WARNING_MESSAGE);
					idtf.requestFocus();
				} else if (nametf2.getText().length() == 0) {
					msg = "이름을 입력하세요.";
					JOptionPane.showMessageDialog(null, msg, "",JOptionPane.WARNING_MESSAGE);
					nametf.requestFocus();
				} else if (emailtf2.getText().length() == 0) {
					msg = "이메일을 입력하세요.";
					JOptionPane.showMessageDialog(null, msg, "",JOptionPane.WARNING_MESSAGE);
					emailtf.requestFocus();
				} else {
					fs.searchPwd(m);
					setVisible(false);
					dispose();
				}				
				break;
			case "Cancel":
				setVisible(false);
				dispose();
				break;
			}

		}

	}

}
